package com.idss.authority.mvc.controller;

import cloud.agileframework.mvc.annotation.AgileInParam;
import cloud.agileframework.mvc.base.RETURN;
import cloud.agileframework.mvc.exception.AbstractCustomException;
import cloud.agileframework.mvc.param.AgileReturn;
import com.idss.authority.mvc.pojo.db.SysApiEntity;
import com.idss.authority.mvc.service.MyService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author 佟盟
 * 日期 2021-08-10 16:25
 * 描述 TODO
 * @version 1.0
 * @since 1.0
 */
@Controller
public class TestController {

	@Autowired
	private MyService service;

	@RequestMapping("/test-db")
	public Object test1() {
		return service.test();
	}


	@RequestMapping("/test")
	public RETURN test(
			@AgileInParam SysApiEntity param2,
			@AgileInParam("demoAList.0.date") Date param3,
			@AgileInParam("demoAList.date") List<Date> param4,
			String a,
			String b) {
		if (param2 == null || param3 == null || param4 == null || a == null) {
			return RETURN.EXCEPTION;
		}
		AgileReturn.add("hello world");
		return RETURN.SUCCESS;
	}

	@RequestMapping("/test1")
	public RETURN test1(@AgileInParam Map<String, Object> param2) {
		if (param2 == null) {
			return RETURN.EXCEPTION;
		}
		AgileReturn.add("param", param2);
		return RETURN.SUCCESS;
	}

	@RequestMapping("/test2")
	public RETURN test2(@AgileInParam Set<String> param2) {
		if (param2 == null) {
			return RETURN.EXCEPTION;
		}
		AgileReturn.add("param", param2);
		return RETURN.SUCCESS;
	}

	@RequestMapping("/test3")
	public Object test() throws MaxUploadSizeExceededException {
		//业务调用
		throw new MaxUploadSizeExceededException(20000L);
	}

	@RequestMapping("/test4")
	public Object test2(String a, String b) throws AbstractCustomException {
		//业务调用
		throw new AbstractCustomException(a,b) {
		};
	}


}
